<%-- 
    Document   : browse
    Created on : Nov 17, 2013, 3:31:22 PM
    Author     : Liem
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>
<jsp:include page="header.jsp"/>
<jsp:include page="leftbar.jsp"/>
<c:if test="${empty sessionScope.USER}">
    <jsp:forward page="login.jsp"/>
</c:if>
<script type="text/javascript">
    function hideEleByClass(matchClass) {
        var elems = document.getElementsByTagName('div');
        for (i in elems) {
            if (elems[i].className != null) {
                if((elems[i].className).indexOf(' ' + matchClass) > -1) {
                    //alert(elems[i].className);
                    elems[i].style.display = 'none';
                }
            }         
        }
    }
    function showEleByClass(matchClass) {
        var elems = document.getElementsByTagName('div');
        for (i in elems) {
            if (elems[i].className != null) {
                if ((elems[i].className).indexOf(' ' + matchClass) > -1) {
                    elems[i].style.display = 'block';
                }
            }
        }
    }

    /**
     * filter by
     */
    function filterPostByStatus(status) {
        if (status == 'approved') {
            hideEleByClass('unread');
            hideEleByClass('read');
            showEleByClass('approved');
        } else if (status == 'unread') {
            hideEleByClass('approved');
            hideEleByClass('read');
            showEleByClass('unread');
        } else if (status == 'read') {
            hideEleByClass('approved');
            hideEleByClass('unread');
            showEleByClass('read');
        } else if (status == 'all') {
            showEleByClass('approved');
            showEleByClass('unread');
            showEleByClass('read');
        }
    }
</script>
<div class="main-wrapper">
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span12">
                <div class="primary-head">
                    <h3 class="page-header">Browse Post</h3>
                </div>
            </div>
        </div>
        <c:if test="${empty sessionScope.HASTOKEN}">
            <div class="row-fluid">
                <div class="span12">
                    <div class="alert alert-error">
                        <button type="button" class="close" onclick="">×</button>
                        <i class="icon-info-sign"></i>
                        Your account has not connect with facebook. Click <a href="getFBAccessToken.action">here</a>
                    </div>

                </div>
            </div>
        </c:if>
        <c:if test="${not empty param.error}">
            <div class="row-fluid">
                <div class="span12">
                    <div class="alert alert-error">
                        <button type="button" class="close" onclick="">×</button>
                        <i class="icon-info-sign"></i>
                        <c:out value="${param.error}"/>
                    </div>
                </div>
            </div>
        </c:if>
        <div class="row-fluid">
            <div class="span12">
                <div class="content-widgets">
                    <div class="widget-container light-gray">                        
                        <h4 class="widget-header">
                            <c:import url="WEB-INF/xml/page.xml" var="pageXml" charEncoding="UTF-8"/>
                            <c:import url="WEB-INF/xsl/getPagename.xsl" var="pageXsl" charEncoding="UTF-8"/>
                            <x:transform xml="${pageXml}" xslt="${pageXsl}">
                                <x:param name="pageId" value="${param.pageId}"/>
                            </x:transform>
                            <div class="pull-right">
                                <a class="btn btn-info" href="#" onclick="filterPostByStatus('all');">View all</a>
                                <a class="btn btn-info" href="#" onclick="filterPostByStatus('unread');">View Unread</a>
                                <a class="btn btn-info" href="#" onclick="filterPostByStatus('read');">View Read</a>
                                <a class="btn btn-info" href="#" onclick="filterPostByStatus('approved');">View Approved</a>
                                <a class="btn btn-info" href="editpage.jsp?pageId=${param.pageId}">
                                    Edit Info</a>
                            </div>
                        </h4>
                    </div>
                </div>

                <c:import url="WEB-INF/xml/post.xml" var="postXml" charEncoding="UTF-8"/>
                <c:import url="WEB-INF/xsl/listPost.xsl" var="postXsl" charEncoding="UTF-8"/>
                <x:transform xml="${postXml}" xslt="${postXsl}">
                    <x:param name="pageId" value="${param.pageId}"/>
                    <x:param name="returnUrl" value="${pageContext.request.requestURL}?${pageContext.request.queryString}"/>
                </x:transform>
            </div>
        </div>
    </div>
</div>

<jsp:include page="footer.jsp"/>
